package com.sxz.sbs.module.client.presenter;

import com.sxz.sbs.app.App;
import com.sxz.sbs.module.client.bean.CallRecordsBean;
import com.sxz.sbs.module.client.view.CallRecordsView;
import com.sxz.sbs.rx.RxPresenter;
import com.sxz.sbs.rx.RxSubscriber;
import com.sxz.sbs.rx.RxUtil;

import java.util.HashMap;
import java.util.List;

/**
 * 通话记录
 */
public class CallRecordsPresenter extends RxPresenter<CallRecordsView>{
    /**
     * @param map
     */
    public void getCallRecords (final HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().getCallRecords(map)
                .compose(RxUtil.<List<CallRecordsBean>>handleResult())
                .subscribeWith(new RxSubscriber<List<CallRecordsBean>>(mView){
                    @Override
                    public void onNext(List<CallRecordsBean> data) {
                        mView.onCallRecordsSuccess(data);
                    }
                })
        );
    }
    /**
     * 添加意向客户
     * @param map
     */
    public void getAddIntentionClient (final HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().getAddIntentionClient(map)
                .compose(RxUtil.<String>handleResult())
                .subscribeWith(new RxSubscriber<String>(mView){
                    @Override
                    public void onNext(String data) {
                        mView.onAddIntentionClientSuccess(data);
                    }
                })
        );
    }
    /**
     * 新增通话记录
     * @param map
     */
    public void addCallRecord (final HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().addCallRecord(map)
                .compose(RxUtil.<String>handleResult())
                .subscribeWith(new RxSubscriber<String>(mView){
                    @Override
                    public void onNext(String data) {
                        mView.onAddCallRecordSuccess();
                    }
                })
        );
    }
}
